#pragma once


#include "CommonStd.h"
#include <string>


class Algorithm
{
	relative_type m_Head;
	Move::Enum m_Move;
	State::Enum m_State;
	relative_type m_Step;


public :
	Algorithm( relative_type head_pos )
	{
		m_Head = head_pos;		
		m_Move = Move::Right;
		m_State = State::_1;
		m_Step = 0;
	}
	~Algorithm( void ) {}


	virtual bool Run( std::string& tape ) = 0;	

	State::Enum GetState( void ) const { return m_State; }
	relative_type GetHead( void ) const { return m_Head; }
	relative_type GetStep( void ) const { return m_Step; }


protected :
	#define ZERO	"0"
	#define ONE		"1"
	#define BLANK	"_"
	#define DUMMY	"#"
	#define MINUS	"-"
	#define PLUS	"+"
	
	void SetHead( relative_type val ) { m_Head = val; }	
	Move::Enum GetMove( void ) const { return m_Move; }
	void MoveLeft( void ) { m_Move = Move::Left; if( 0 == GetHead() ) { return; } SetHead( GetHead() - 1 ); }
	void MoveRight( void ) { m_Move = Move::Right; SetHead( GetHead() + 1 ); }	
	void SetState( State::Enum val ) { m_State = val; }
	void New( std::string& target, const char* val, relative_type pos ) { target.insert( pos, val ); }
	void Delete( std::string& target, relative_type pos ) { target.erase( pos, 1 ); }
	void SetStep( relative_type val ) { m_Step = val; }
};